﻿<!DOCTYPE HTML>
<html>
<head>
	@include('common.header')
	<title>商品管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 商品管理 <span class="c-gray en">&gt;</span> 商品管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<form action="{{url('Goods/list.html')}}" method="post" class="text-l">
		<span class="select-box inline">
		<select name="cat_id" class="select">
			<option value="" <?php if(!isset($search_data['cat_id'])): ?>selected="selected"<?php endif; ?>>全部分类</option>
			@foreach($cats as $cat)
			<option value="{{$cat['id']}}" <?php if(isset($search_data['cat_id']) && $search_data['cat_id']==$cat['id']): ?>selected="selected"<?php endif; ?>>{{str_repeat('&nbsp;',$cat['depth']*4)}}{{$cat['name']}}</option>
			@endforeach
		</select>
		</span>
		<input type="text" name="title" id="title" placeholder="商品名称" style="width:125px" class="input-text" value="{{$search_data['title'] or null}}">
		<button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
	</form>
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a href="javascript:;" onclick="datadel()" class="btn btn-danger"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
			<a class="btn btn-primary" onclick="show_frame('添加商品','{{url('Goods/edit.html')}}',800,550)" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加商品</a>
		</span>
		<span class="r">共有数据：<strong>{{count($list)}}</strong> 条</span>
	</div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
			<thead>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				{{--<th width="80">ID</th>--}}
				<th>标题</th>
				<th>货号</th>
				<th>图片</th>
				<th>分类</th>
				<th>品牌</th>
				<th>售价</th>
				<th>库存</th>
				<th>销量</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
				@foreach($list as $v)
				<tr class="text-c">
					<td width="25"><input type="checkbox" value="{{$v['id']}}" name="ids"></td>
					{{--<td width="80">{{$v['id']}}</td>--}}
					<td>{{$v['title']}}</td>
					<td>{{$v['item_no']}}</td>
					<td>
						@if($v['img'])
							<img src="{{$v['img']}}" width="90" height="60">
						@endif
					</td>
					<td>{{$v['cat_name']}}</td>
					<td>{{$v['brand_name']}}</td>
					<td>{{$v['sell_price']}}</td>
					<td>{{$v['stock']}}</td>
					<td>{{$v['sales_volumn']}}</td>
					<td class="f-14 td-manage">
						<button class="ml-5 btn btn-success" onclick="show_frame('编辑','{{url('Goods/edit.html')}}?id={{$v['id']}}',800,550)" title="编辑">编辑</button>
						<button class="ml-5 btn btn-danger" onclick="del(this,{{$v['id']}});" title="删除">删除</button>
					</td>
				</tr>
				@endforeach
			</tbody>
		</table>
	</div>
</div>
@include('common.footer')

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="{{asset('hui-admin/lib/My97DatePicker/4.8/WdatePicker.js')}}"></script>
<script type="text/javascript" src="{{asset('hui-admin/lib/datatables/1.10.0/jquery.dataTables.min.js')}}"></script>
<script type="text/javascript" src="{{asset('hui-admin/lib/laypage/1.2/laypage.js')}}"></script>
<script type="text/javascript">
    $('.table-sort').dataTable({
        // "aaSorting": [[ 1, "desc" ]],//默认第几个排序
        "bStateSave": true,//状态保存
        "pading":false,
        "aoColumnDefs": [
            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
            {"orderable":false,"aTargets":[0,1,2,3,4,5,9]}// 不参与排序的列
        ]
    });

    function show_frame(title,url,w,h){
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }

    function del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: '/Goods/del',
                data: {'id':id},
                dataType: 'json',
                success: function(data){
                    if(data.code == 1){
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                    }else{
                        layer.msg('删除失败',function () {});
                    }
                }
            });
        });
    }

    function datadel(){
        var ids = [];
        $("input[name=ids]:checked").each(function(i){
            ids[i] = $(this).val();
        });
        var id = ids.join(',');
        if(isNull(id)){
            layer.msg('请选择批量删除的商品',function () {});
        }else{
            layer.confirm('确认要删除这些商品吗？',function(index){
                $.ajax({
                    type: 'POST',
                    url: '/Goods/del',
                    data: {'id':id},
                    dataType: 'json',
                    success: function(data){
                        if(data.code == 1){
                            layer.msg('已删除!',{icon:1,time:1000});
                            refresh();
                        }else{
                            layer.msg('删除失败',function () {});
                        }
                    }
                });
            });
        }
    }

</script>
</body>
</html>